﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using com.lover.astd.common.manager;
using com.lover.astd.common.model;
using com.lover.common;

namespace com.lover.astd.weaponcalc
{
    public partial class WeaponCalc : Form
    {
        public WeaponCalc()
        {
            InitializeComponent();
        }

        private void btn_calcRed_Click(object sender, EventArgs e)
        {
            int weaponIndex = lst_redWeapon.SelectedIndex;
            if (weaponIndex < 0)
            {
                UiUtils.getInstance().info("还未选择红兵器呢");
                return;
            }
            int weaponAmount = (int)num_redAmount.Value;
            Equipment equip = new Equipment();
            equip.goodstype = GoodsType.Weapon;
            equip.Quality = EquipmentQuality.Red;
            equip.Type = (EquipmentType)Enum.Parse(typeof(EquipmentType), (weaponIndex+1).ToString());
            equip.ValueNow = weaponAmount;

            int weaponStandard = WeaponHelper.getRedWeaponBaseAmount(equip);
            int weaponMax = WeaponHelper.getRedWeaponMaxAmount(equip);
            
            if (weaponAmount < weaponStandard)
            {
                UiUtils.getInstance().info("你输入的还没基础值高呢, 搞啥呢小伙?");
                return;
            }
            if (weaponAmount > weaponMax)
            {
                UiUtils.getInstance().info("你输入的太高了, 忽悠我呢呢小伙?");
                return;
            }

            int amount_expect, failcount, needcount; double toughness, full_toughness;
            int star = WeaponHelper.calcRedWeaponStar(equip);
            WeaponHelper.getWeaponInfo(equip, 0, out amount_expect, out toughness, out full_toughness, out failcount, out needcount);

            String result = String.Format("当前星级:\t{0:d}星\r\n升星后:\t{1:d}\r\n坚韧度:\t{2:f2}%\r\n失败次数:\t{3:d}\r\n还需失败:\t{4:d}",
                star, amount_expect, toughness * 100, failcount, needcount);

            txt_redResult.Text = result;
        }

        private void btn_calcPurple_Click(object sender, EventArgs e)
        {
            int weaponAmount = (int)num_purpleAmount.Value;
            int star = (int)num_purpleStar.Value;
            int star_expect = (int)num_purpleStarExpect.Value;
            int type = lst_purpleWeapon.SelectedIndex;
            if (type < 0)
            {
                UiUtils.getInstance().info("还没有选择紫色兵器");
                return;
            }

            Equipment equip = new Equipment();
            equip.goodstype = GoodsType.Weapon;
            equip.Quality = EquipmentQuality.Purple;
            equip.Type = (EquipmentType)Enum.Parse(typeof(EquipmentType), (type+1).ToString());
            equip.ValueNow = weaponAmount;
            equip.Level = star;

            int standard = WeaponHelper.getPurpleWeaponBaseAmount((int)equip.Type-1, equip.Level);
            if (weaponAmount < standard)
            {
                UiUtils.getInstance().info("你写的还没有基础值高, 搞虾米呢??");
                return;
            }
            int amount_expect, failcount, needcount; double toughness, full_toughness;
            WeaponHelper.getWeaponInfo(equip, star_expect, out amount_expect, out toughness, out full_toughness, out failcount, out needcount);

            String result = String.Format("当前星级:\t{0:d}\r\n基础值:\t{1:d}\r\n坚韧度:\t{2:f2}%\t(失败次数: {3:d})\r\n满坚韧度:\t{4:f2}%\r\n期望星级:\t{5:d}\r\n期望数值:\t{6:d}",
                star, standard, toughness * 100, failcount, full_toughness * 100, star_expect, amount_expect);
            txt_purpleResult.Text = result;
        }
    }
}
